package com.download.database;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Transaction;
import android.arch.persistence.room.Update;

import java.util.List;

/**
 * Created by chensuilun on 2019/3/13.
 */
@Dao
public abstract class TsDao {
    static final String V2_ADD_KEY = "ALTER TABLE ts_tasks ADD COLUMN " + TsKey.COL_KEY + " BLOB";
    static final String V2_ADD_IV = "ALTER TABLE ts_tasks ADD COLUMN " + TsKey.COL_IV + " BLOB";

    @Query("select * from ts_tasks where parentId = :m3u8Id order by seg_index")
    public abstract List<TsTask> getAllTsTask(long m3u8Id);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    public abstract void insert(TsTask tsTask);

    @Transaction
    public void insertAll(List<TsTask> tasks) {
        for (TsTask task : tasks) {
            insert(task);
        }
    }

    @Delete
    public abstract void delete(TsTask tsTask);

    @Transaction
    public void deleteAll(List<TsTask> tasks) {
        for (TsTask task : tasks) {
            delete(task);
        }
    }

    @Update(onConflict = OnConflictStrategy.REPLACE)
    public abstract void update(TsTask tsTask);

}
